package com.twu.biblioteca.book;

import com.twu.biblioteca.IOStream.Message;
import com.twu.biblioteca.book.Book;

import java.util.Vector;


public class Books {
    private Vector<Book> books;

    public Books() {
        this.books = new Vector<Book>();
    }

    public Vector<Book> getBooks() {
        return this.books;
    }

    public void addBook(Book book) {
        this.books.addElement(book);
    }

    public Message viewAllBooksMessage() {
        StringBuffer booksString = new StringBuffer();
        for (int i = 0; i < this.books.size(); i++) {
            booksString.append(this.books.elementAt(i).toString());
        }
        return new Message(booksString.toString());
    }

    public Book findBookById(int id) {
        for (int i = 0; i < this.books.size(); i++) {
            if (this.books.elementAt(i).getId() == id)
                return this.books.elementAt(i);
        }
        return null;
    }
}
